<?php
namespace controller;
require_once('model/login.php');
require_once('view/pageView.php');

class Control{
	
	//@var new \model\Login;
	private $model;
	//@var \view\PageView;
	private $view;
	//@var array
	private $array;
	
	public function __construct(){
		$this->model = new \model\Login();
		$this->view = new \view\PageView();
	}
	
	 /*
	 * return string (message)
	 */	
	public function checkControl(){
		
		if($this->view->getlogOutButton() == TRUE){
			$messageNr = $this->model->logOut();
		}else if($this->model->checkIfLoggedIn() == TRUE){
			$messageNr = $this->model->checkSession();
		}else if($this->view->getcookieUsername() != FALSE 
			  && $this->view->getcookieUsername() != FALSE){
			  	
			$cookieUsername = $this->view->getcookieUsername();
			$cookiePassword = $this->view->getcookiePassword();	  
			$messageNr = $this->model->checkCookies($cookieUsername, $cookiePassword);
		
		}else if($this->view->getlogInButton() == TRUE){
			$username = $this->view->getUsername();
			$password = $this->view->getPassword();
			$messageNr = $this->model->tryLogIn($username, $password);
		}else{
				$messageNr = 0;
		}
		return $messageNr;
	}
	
	/*
	 * @return string (HTML)
	 */
	public function getHTML(){
		try {
			$messageNr = $this->checkControl();
			$sessionLoggedIn = $this->model->checkIfLoggedIn();
			return $this->view->checkIfLoggedIn($messageNr, $sessionLoggedIn);
		}catch(Exception $e){
			echo"Something wrong in controller";
		}
	}
}
 
